// pages/project/list/list.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    //tab切换  
    currentTab: 0,
    //modal
    isShow: false,
    projectList: [],
    searchParams: {
      status: null,
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    if (options.type == 1) {
      wx.setNavigationBarTitle({
        title: '我的课堂'
      })
    }
    if (options.type == 2) {
      wx.setNavigationBarTitle({
        title: '我的会议'
      })
    }
    if (options.type == 3) {
      wx.setNavigationBarTitle({
        title: '我的会议'
      })
    }

    //获取类别 1课堂、2会议、3活动
    var projectType = options.type
    var searchParams = this.data.searchParams
    searchParams.projectType = projectType

    this.setData({
      searchParams: searchParams
    })
    this.getProjectList();

  },

  getProjectList: function(e) {
    wx.showLoading({
      title: '加载中',
    })
    var that = this
    wx.request({
      url: app.host + '/project/myProject',
      data: that.data.searchParams,
      header: {
        accessToken: app.accessToken
      },
      method: "post",
      complete: function(res) {
        wx.hideLoading()
        console.log(res)
        if (res.statusCode == 200) {
          if (res.data.code == 0) {
            that.setData({
              projectList: res.data.data
            })
          }
        }
      }
    })
  },

  toProjectDetail: function(res) {
    console.log(res)
    var projectId = res.currentTarget.dataset.id
    wx.navigateTo({
      url: '/pages/portal/project/detail/detail?id=' + projectId,
    })
  },

  // 操作model
  showModal(e) {
    this.setData({
      isShow: true
    })
  },
  hideModal(e) {
    this.setData({
      isShow: false
    })
  },

  /** 控制顶部nav */
  swichNav: function(e) {
    console.log(e)
    var that = this;
    if (this.data.currentTab === e.target.dataset.current) {
      return false;
    } else {
      var searchParams = that.data.searchParams
      if (e.target.dataset.current == 0) {
        searchParams.status = null
      } else {
        searchParams.status = e.target.dataset.current
      }
      that.setData({
        searchParams: searchParams,
        currentTab: e.target.dataset.current
      })
      that.getProjectList()
    }
  },



})